def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

def closest_prime_number(n):
    if is_prime(n):
        return n
    lo = n - 1
    up = n + 1
    while True:
        if is_prime(lo):
            return lo
        elif is_prime(up):
            return up
        lo -= 1
        up += 1

inw = input().split()
if len(inw) != 3:
    print("Wrong input")
else:
    r = ""
    for word in inw:
        if word == "zero":
            r += "0"
        elif word == "one":
            r += "1"
        elif word == "two":
            r += "2"
        elif word == "three":
            r += "3"
        elif word == "four":
            r += "4"
        elif word == "five":
            r += "5"
        elif word == "six":
            r += "6"
        elif word == "seven":
            r += "7"
        elif word == "eight":
            r += "8"
        elif word == "nine":
            r += "9"
    if len(r) != 3 or not r.isdigit():
        print("Wrong input")
    else:
        r = int(r)
        result = closest_prime_number(r)
        print(result)
